<template>
  <div class="chartNum flexStart">
    <div class="box-item">
      <li
        :class="{'number-item': !isNaN(item), 'mark-item': isNaN(item) }"
        v-for="(item,index) in orderNum"
        :key="index"
      >
        <span v-if="!isNaN(item)">
          <i ref="numberItem">0123456789</i>
        </span>
        <span class="comma" v-else>{{item}}</span>
      </li>
    </div>
    <!-- <div style="width:100%;height:50px"></div> -->
    <div style="font-size: 3rem;font-weight: 400;color: #5CFFFF;line-height:3rem">元</div>
  </div>
</template>
<script>

export default {
  data() {
    return {
      orderNum: ['0', '0', '0',',', '0', '0', '0', ',','0', '0', '0'], // 默认订单总数
      num:this.$store.state.wagePay.wageTotal
    }
  },
  mounted() {

    setTimeout(() => {
      this.toOrderNum(this.$store.state.wagePay.wageTotal) // 这里输入数字即可调用
    }, 500)
  },
  methods: {
    // 设置文字滚动
    setNumberTransform() {
      const numberItems = this.$refs.numberItem // 拿到数字的ref，计算元素数量
      // console.log(numberItems);
      
      const numberArr = this.orderNum.filter((item) => !isNaN(item))
      // 结合CSS 对数字字符进行滚动,显示订单数量
      for (let index = 0; index < numberItems.length; index++) {
        const elem = numberItems[index]
        elem.style.transform = `translate(-50%, -${numberArr[index] * 10}%)`
      }
    },
    // 处理总订单数字
    toOrderNum(num) {
      
      // console.log(num);
      
      num = num.toString()
      // console.log(num.length);
      
      // 把订单数变成字符串
      if (num.length < 9) {
        num = '0' + num // 如未满八位数，添加"0"补位
        // console.log(num);
        
        this.toOrderNum(num) // 递归添加"0"补位
      } else if (num.length == 9) {
        // 订单数中加入逗号
        num = num.slice(0, 3) + ',' + num.slice(3, 6) + ',' + num.slice(6, 9)
        // console.log(num);
        
        this.orderNum = num.split('') // 将其便变成数据，渲染至滚动数组
        // console.log(this.orderNum);
        
      } else {
        // 订单总量数字超过九位显示异常
        this.$message.warning('总量数字过大')
      }
      this.setNumberTransform()
    }
  }
}
</script>
<style scoped lang='less'>
.flexStart {
  align-items: flex-end;
}
/*订单总量滚动数字设置*/
.box-item {
  position: relative;
  height: 10.7rem;
  font-size: 9.1rem;
  line-height: 7rem;
  text-align: center;
  list-style: none;
  color: #01fff6;
  writing-mode: vertical-lr;
  text-orientation: upright;
  margin-right: 2rem;
  // background: #13264f;

  font-family: 'DigifaceWide';
}
/* 默认逗号设置 */
.mark-item {
  width: 1rem;
  height: 12rem;
  margin-right: 2rem;
  line-height: 1rem;
  font-size: 9.1rem;
  position: relative;
  & > span {
    position: absolute;
    width: 100%;
    bottom: 0;
    writing-mode: vertical-rl;
    text-orientation: upright;
  }
}
/*滚动数字设置*/
.number-item {
  width: 8rem;
  height: 10.7rem;
  /* 背景图片 */
  background: url('../../../../../../assets/img/numBoder.png') no-repeat 0.3rem;
  // border: 0.1rem solid;
  // border-image: linear-gradient(0deg, rgba(0, 180, 255, 0.8), rgba(0, 180, 255, 0.8)) 1 1;
  border-radius: 0.3rem;
  background-size: 100% 100%;

  list-style: none;
  margin-right: 2rem;

  & > span {
    position: relative;
    display: inline-block;
    margin-right: 0.1rem;
    width: 100%;
    height: 100%;
    writing-mode: vertical-rl;
    text-orientation: upright;
    overflow: hidden;
    & > i {
      font-style: normal;
      position: absolute;
      top: -0.55rem;
      left: 49%;
      transform: translate(-50%, 0);
      transition: transform 1s ease-in-out;
      letter-spacing: 1rem;
    }
  }
}
.number-item:last-child {
  margin-right: 0;
}
</style>